package com.wizinno.android.urineflow.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;
import com.wizinno.android.urineflow.constant.CommonControl;
import com.wizinno.android.urineflow.thread.UsbInitThread;
import com.wizinno.android.urineflow.util.LogUtils;

/**
 * @author LiuMei
 * @date 2020-12-23.
 */
public class USBPlugReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
            LogUtils.d("插入USB设备");
            UsbInitThread usbThread = new UsbInitThread();
            usbThread.start();
        } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
            LogUtils.d("拔出USB设备");
            CommonControl.usbInit();
        }
    }
}
